<template>
	<view class="container">
		<unicloud-db ref="udb" v-slot:default="{data, pagination, loading, hasMore, error}"
			:where="`user_id==$cloudEnv_uid`" orderby="comment_date desc" :collection="collectionList"
			field="comment_content,comment_date,article_id">
			<view v-if="error">{{error.message}}</view>
			<view v-else-if="data">
				<uni-list>
					<uni-list-item v-for="(item, index) in data" :key="index" showArrow :clickable="true"
						@click="handleItemClick(item.article_id)">
						<template v-slot:body>
							<view class="">
								<view class="title">
									{{item.comment_content}}
								</view>
								<view class="releasetime">
									<uni-dateformat :date="item.comment_date" :threshold="[60000, 3600000]"
										format="yyyy年MM月dd hh:mm:ss"></uni-dateformat>
								</view>
							</view>
						</template>
					</uni-list-item>
				</uni-list>
			</view>
			<uni-load-more :status="loading?'loading':(hasMore ? 'more' : 'noMore')"></uni-load-more>
		</unicloud-db>
	</view>
</template>

<script>
	const db = uniCloud.database()
	export default {
		data() {
			return {
				collectionList: "cloud_fishCircle-comments",
				loadMore: {
					contentdown: '',
					contentrefresh: '',
					contentnomore: ''
				}
			}
		},
		onPullDownRefresh() {
			this.$refs.udb.loadData({
				clear: true
			}, () => {
				uni.stopPullDownRefresh()
			})
		},
		onReachBottom() {
			this.$refs.udb.loadMore()
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: '我的评论'
			});
		},
		methods: {
			handleItemClick(id) {
				uni.navigateTo({
					url: '/pages/detail/detail?id=' + id
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		.title {
			font-size: 34rpx;
			@include text-omission(1);
		}

		.releasetime {
			color: #888;
			font-size: 24rpx;
		}
	}
</style>